package com.ibeeking.found.msg.rest.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibeeking.found.msg.rest.service.IMsgRecordService;
import com.ibeeking.found.msg.service.common.param.MsgRecordParam;
import com.ibeeking.found.msg.service.common.query.MsgRecordPageQuery;
import com.ibeeking.found.msg.service.common.query.MsgRecordQuery;
import com.ibeeking.found.msg.service.common.vo.MsgRecordAttachVO;
import com.ibeeking.found.msg.service.common.vo.MsgRecordVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName MsgRecordController
 * @Description
 * @Author ibeeking
 * @Date 2022-03-17 14:47
 **/
@RestController
@RequestMapping("/msg/msgRecord/v1")
public class MsgRecordController {

    @Resource
    private IMsgRecordService msgRecordServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息列表")
    @PostMapping(value = "/list")
    public List<MsgRecordVO> list(@RequestBody MsgRecordQuery query) {
        return msgRecordServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "首页消息列表")
    @PostMapping(value = "/listSimpleWiki/{rows}")
    public List<MsgRecordVO> list(@PathVariable("rows") Integer rows) {
        return msgRecordServiceImpl.listEffectSimpleMsg(rows);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息分页列表")
    @PostMapping(value = "/pageList")
    public Page<MsgRecordVO> pageList(@RequestBody MsgRecordPageQuery pageQuery) {
        return msgRecordServiceImpl.pageList(pageQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "新增消息")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) MsgRecordParam param)  {
        return msgRecordServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改消息")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) MsgRecordParam param) {
        return  msgRecordServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息详情")
    @PostMapping(value = "/view/{id}")
    public MsgRecordVO view(@PathVariable("id") Long id) {
        return msgRecordServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改消息状态")
    @PostMapping(value = "/changeReadStatus/{id}/{status}")
    public Boolean changeReadStatus(@PathVariable("id") Long id,@PathVariable("status") Integer status) {
        return  msgRecordServiceImpl.changeReadStatus(id,status);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除消息")
    @PostMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return  msgRecordServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "消息附件列表")
    @PostMapping(value = "/listAttachsByMsgId/{msgId}")
    public List<MsgRecordAttachVO> listAttachsByWikiId(@PathVariable("msgId") Long msgId) {
        return msgRecordServiceImpl.listAttachsByMsgId(msgId);
    }
}
